//package com.tsinghuabigdata.edu.ddmath.MVPPresent;
//
//import android.content.Context;
//import android.os.Handler;
//import android.os.Message;
//
//import com.blueto.cn.myutils.localcache.PreferencesUtils;
//import com.tsinghuabigdata.edu.zxapp.teacher.MVPModel.MessageModel;
//import com.tsinghuabigdata.edu.zxapp.teacher.MVPModel.RequestListener;
//import com.tsinghuabigdata.edu.zxapp.teacher.VolleryRequest.HttpResponse;
//import com.tsinghuabigdata.edu.zxapp.teacher.bean.IsExistNewMsgResult;
//import com.tsinghuabigdata.edu.zxapp.teacher.bean.MessageInfo;
//import com.tsinghuabigdata.edu.zxapp.teacher.broadcast.JPushClientReceiver;
//import com.tsinghuabigdata.edu.zxapp.teacher.constant.AppConst;
//import com.tsinghuabigdata.edu.zxapp.teacher.utils.AccountUtils;
//import com.tsinghuabigdata.edu.zxapp.teacher.utils.HomeMsgManager;
//
//import java.util.List;
//
//
///**
// * Created by 28205 on 2016/9/2.
// */
//public class MainActivityPresenter extends MVPBasePresent {
//    private static final String TAG = "MainActivityPresenter";
//
//    private static final int HOME_MSG_LOAD_SUCCESS = 1000;
//    private static final int ISEXIST_NEW_MSG_REQ_SUCCESS = 1001;
//
//    private MessageModel messageModel;
//
//    final String userId;
//    final String accessToken;
//    private Context context;
//
//    private Handler mHandler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            switch (msg.what) {
//                case HOME_MSG_LOAD_SUCCESS:
//                    break;
//                case ISEXIST_NEW_MSG_REQ_SUCCESS:
//                    IsExistNewMsgResult res = (IsExistNewMsgResult) msg.obj;
//                    if (res.isWdxx() || res.isZxtj()) {
//                        JPushClientReceiver.sendNewMsgBrd(context, true);
//                        PreferencesUtils.putBoolean(context, AppConst.MSG_TYPE_MYMSG, res.isWdxx());
//                        PreferencesUtils.putBoolean(context, AppConst.MSG_TYPE_REC, res.isZxtj());
//                    }
//                    break;
//            }
//        }
//    };
//
//    public MainActivityPresenter(Context context) {
//        messageModel = new MessageModel();
//        userId = AccountUtils.getTeacherDetailInfo().getTeacherId();
//        accessToken = AccountUtils.getLoginUser().getAccess_token();
//        this.context = context;
//    }
//
//    public void queryHomeMsg(final boolean isNowSaveNextHomeMsg) {
//        messageModel.queryHomeMsg(accessToken, userId, new RequestListener() {
//            @Override
//            public void onSuccess(Object res) {
//                saveHomeMsgCache((List<MessageInfo>) res, isNowSaveNextHomeMsg);
//            }
//
//            @Override
//            public void onFail(HttpResponse response, Exception ex) {
//
//            }
//
//        });
//    }
//
//    public void queryIsexistNewMsg(String msgColumn) {
//        messageModel.queryIsexistNewUserMsgInfo(accessToken, userId, msgColumn, new RequestListener<IsExistNewMsgResult>() {
//            @Override
//            public void onSuccess(IsExistNewMsgResult res) {
//                Message msg = Message.obtain();
//                msg.what = ISEXIST_NEW_MSG_REQ_SUCCESS;
//                msg.obj = res;
//                mHandler.sendMessage(msg);
//            }
//
//            @Override
//            public void onFail(HttpResponse response, Exception ex) {
//            }
//        });
//    }
//
//    private void saveHomeMsgCache(List<MessageInfo> resultInfo, boolean isNowSaveNextHomeMsg) {
//        //获取到的图片消息为空，采用上一次缓存的内容
//        if (resultInfo == null) {
//            return;
//        }
//        HomeMsgManager homeMsgManager = HomeMsgManager.getInstance();
//        homeMsgManager.setNextHomeMsgs(resultInfo);
//        if (isNowSaveNextHomeMsg) {
//            homeMsgManager.saveHomeMsg(context, homeMsgManager.getNextHomeMsgs());
//        }
//    }
//
//}
